<?php
header('Content-type:text/json');     //这句是重点，它告诉接收数据的对象此页面输出的是json数据；  

$chat_id=$_GET['chat_id'];
$vod_id=$_GET['vod_id'];


include 'db.php';/*连接数据库*/

//统计有多少个新聊天数据
$chat_number_tj=0;
$result = mysql_query("SELECT * FROM vod_chat");
	while($row = mysql_fetch_array($result))
	{    
		if ($row['id']>$chat_id){
			$chat_number_tj=$chat_number_tj+1;
			}
	}

//生成JSON数据
$chat_number=0;
$result = mysql_query("SELECT * FROM vod_chat");
	while($row = mysql_fetch_array($result))
	{   
	    
		if ($row['id']>$chat_id){
			$chat_number=$chat_number+1;
			if ($chat_number_tj==1){
				$chat_json=$chat_json."{'chat_content':[{'chat".$chat_number."':[{'openid':'".$row['openid']."','user_cid':'".$row['id']."','user_name':'".$row['user_name']."','user_head':'".$row['user_head']."','user_talk':'".$row['user_talk']."'}]}],";
				}else{
				if ($chat_number==1){
					$chat_json=$chat_json."{'chat_content':[{'chat".$chat_number."':[{'openid':'".$row['openid']."','user_cid':'".$row['id']."','user_name':'".$row['user_name']."','user_head':'".$row['user_head']."','user_talk':'".$row['user_talk']."'}],";
					}
				if ($chat_number!=1 and $chat_number!=$chat_number_tj){
					$chat_json=$chat_json."'chat".$chat_number."':[{'openid':'".$row['openid']."','user_cid':'".$row['id']."','user_name':'".$row['user_name']."','user_head':'".$row['user_head']."','user_talk':'".$row['user_talk']."'}],";
					}
				if ($chat_number==$chat_number_tj){
					$chat_json=$chat_json."'chat".$chat_number."':[{'openid':'".$row['openid']."','user_cid':'".$row['id']."','user_name':'".$row['user_name']."','user_head':'".$row['user_head']."','user_talk':'".$row['user_talk']."'}]}],";
					}
				}
			}
	}


$result = mysql_query("SELECT * FROM vod_project where id=".$vod_id);
	while($row = mysql_fetch_array($result))
	{   
	$chat_json=$chat_json."'user_number':'".$row['number']."'}";
	}



        //返回值
        $callback = $_GET['callback'];  
		echo "{$callback}(".$chat_json.")";  
        exit();  
  







?>